<?php
/*
	我的下线
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
if($_RQ['op']=='main'){
	if($_RQ['is_access']){
		$member=$this->model('member')->checkmember('',true);
	}else{
		$member=$this->model('member')->checkmember('',false);
	}
	$return['setting']=$this->plugin_setting('page_setting');
	$levels=array();
	$return['allagentnum']=$this->count('member',array('agent_id'=>$_SESSION['uid']));
	$return['levels']=$levels;
	
	$return['params']=array('page'=>1,'level'=>1);
	$return['psize']=20;
	$return['list']=array();
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
	$member2=$this->get('member',array('mid'=>$_SESSION['uid']));
	$member['salefee']=$this->sum('order',array('uniacid'=>$_SESSION['uniacid'],'agent_id'=>$_SESSION['uid']),'price');
	$member=array_merge($member2,$member);
	$return['member']=$member;
	set_html('title',$return['setting']['tmydown']?:'我的下线');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$agent_ids=$_SESSION['uid'];
	if(!$agent_ids){
		exi('none');
	}
	$params['agent_id']=$agent_ids;
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'mid desc',
	);
	$list=$this->get_list('member',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['member']=cfc('core')->member_show($item['mid']);
		if(!$item['member']['id']){
			pdo_delete('jy_boaoshop_member',array('mid'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));	
		}
		$item['agenttime']=date('Y-m-d H:i:s',$item['agenttime']);
		$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		$item['member_num']=$this->count('member',array('agent_id'=>$item['mid']),array('mid'),'mid');
		$item['leveltitle']=$this->getcolumn('level',array('id'=>$item['level_id']),'title');
		$item['leveltitle']=$item['leveltitle']?:'默认等级';
	}
	exi($list);
}
?>